<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Logistics1 extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'logistics1';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
//        'is_default_text'
    ];


    public function getIsDefaultList()
    {
        return ['1' => __('Is_default 1'), '2' => __('Is_default 2')];
    }


    public function getIsDefaultTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_default']) ? $data['is_default'] : '');
        $list = $this->getIsDefaultList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getTypeList()
    {
        return ['1' => __('按重量'), '2' => __('按件数')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    /*
     * 计算价格
     * 1,19,37,220,351,466,585,655,801,820,933,1046,1168,1263,1532,1709,1827,1964,2162,2291,2323,2367,2572,2670,2816,2898,3022,3126,3178,3206,3325,3716,3738
     * */
    public static function getPrice($weight=0,$city=''){
        $where['id']=5;
//        $info = self::where($where)
//            ->find();
        $LogisticsFee1 = LogisticsFee1::where(['logistics_id'=>5,'city_name'=>['in',$city]])->find();
        $price = $LogisticsFee1['first_weight_price'];
        $next_weight_price=0;
        $next_weight_price1 = $LogisticsFee1['next_weight_price'];
        if($weight>$LogisticsFee1['first_weight']){
            $first_weight = $weight-$LogisticsFee1['first_weight'];//计算重量
//            dd($first_weight);
            $next_weight_price = $next_weight_price1*$first_weight;
        }
        $price = $price+$next_weight_price;
//        dd($price);
        return $price;
    }


}
